function Carousel(container,options){
	this.initFlag = 1;
	this.count = 0;
	var ctrl = this,
		container = document.querySelector(container);
	this.options = options;
	this.items = container.querySelectorAll('.banner-item' );
	this.itemLen = this.items.length;
	this.wrapper = container.querySelector('.banner-wrapper');
	this.pagination = container.querySelector('.pagination');
	this.timer = null;
	this.init(document);	
}

Carousel.prototype.screenWidth = document.body.clientWidth;

Carousel.prototype.init = function(doc){
	if(this.initFlag==1){
		this.initFlag = null;
	} else{
		console.log('尝试初始化两次以上！');
		return;
	}
	var c = this,
	    screenWidth = this.screenWidth,
		items = c.items,
		itemLen = c.items.length,
		wrapper = c.wrapper,
		pagination = c.pagination,
		timer = c.timer,
		options = c.options;
	wrapper.style.width = screenWidth * (itemLen + 1) + 'px';
	
	for(var i = 0; i < itemLen; i++){
		items[i].style.width = screenWidth + 'px';
		pagination.appendChild(doc.createElement('a'));
	} 
	pagination.querySelector('a').className = 'active';
	wrapper.appendChild(items[0].cloneNode(true));		//追加第一张的克隆节点
	timer = setTimeout(function(){
		c.move(options.interval,options.speed);
	},0);
	var btns = pagination.querySelectorAll('a'),
	btnLen = btns.length;
	for( var i = 0; i<btnLen; i++){
		btns[i].index = i;
		btns[i].onclick=function(){
			clearTimeout(c.timer);
			c.wrapper.style.left = '-' + c.screenWidth * this.index + 'px';
			for(var j = 0; j < btnLen; j++){
				btns[j].removeAttribute ('class');  //清除属性
			}
			this.className = 'active';	
			c.count = this.index;
			c.timer = setTimeout(function(){
				c.move(options.interval,options.speed);
			},options.speed);
		}
	} 
}


Carousel.prototype.move = function (interval,speed){
	console.log(speed);
	var c = this,
		btns = c.pagination.querySelectorAll('a'),
		btnLen = btns.length;
	if(c.count > c.itemLen-1){
		c.wrapper.style.left = '-'+c.count*c.screenWidth+'px';
		for(var i = 0;i<btnLen;i++){
			btns[i].removeAttribute('class');
		}
		btns[0].className = 'active';	//要等待过渡效果
		setTimeout(function(){
			c.wrapper.style.transition = 'left 0s';
			c.count = 0; 
			clearTimeout(c.timer);
			c.timer = setTimeout(function() {
				c.move(interval,speed);
			},0);
		},speed-20);
		return;
	}
	c.wrapper.style.left = '-' + c.count * c.screenWidth + 'px';
	if(c.count == 0){
		setTimeout(function(){
			c.wrapper.style.transition = 'left ' + speed +'ms';
		},20)
		
	}
	btns.forEach(function(e,i){
		e.removeAttribute('class'); 
	});
	btns[c.count++].className = 'active';	
	c.timer = setTimeout(function(){
		c.move(interval,speed);
	},interval);
}